package com.findFish.web.controller.monitor;

import com.findFish.common.core.controller.BaseController;
import com.findFish.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 监控数据控制器
 */
@RestController
@RequestMapping("/monitor/data")
public class MonitorDataController extends BaseController {
    
    private final Random random = new Random();
    
    /**
     * 获取首页监控数据
     */
    @GetMapping("/dashboard")
    public AjaxResult getDashboardData() {
        Map<String, Object> data = new HashMap<>();
        
        // 网络监测数据
        Map<String, Object> networkData = new HashMap<>();
        networkData.put("stability", 98.5 + random.nextDouble() * 1.5);
        networkData.put("latency", 100 + random.nextInt(50));
        networkData.put("activeDevices", 10 + random.nextInt(5));
        data.put("network", networkData);
        
        // 机器监测数据
        Map<String, Object> machineData = new HashMap<>();
        machineData.put("runningRate", 90 + random.nextDouble() * 10);
        machineData.put("runningDevices", 8 + random.nextInt(3));
        machineData.put("maintenanceDevices", 2 + random.nextInt(2));
        data.put("machine", machineData);
        
        // 养殖监测数据
        Map<String, Object> aquacultureData = new HashMap<>();
        aquacultureData.put("waterTemp", 25 + random.nextDouble() * 2);
        aquacultureData.put("phValue", 7.0 + random.nextDouble() * 0.5);
        aquacultureData.put("monitoringPoints", 12 + random.nextInt(5));
        data.put("aquaculture", aquacultureData);
        
        // 环境监测数据
        Map<String, Object> environmentData = new HashMap<>();
        environmentData.put("envTemp", 23 + random.nextDouble() * 3);
        environmentData.put("humidity", 60 + random.nextDouble() * 10);
        environmentData.put("monitoringStations", 8 + random.nextInt(4));
        data.put("environment", environmentData);
        
        // 24小时趋势数据
        Map<String, Object> trendData = new HashMap<>();
        String[] times = {"00:00", "03:00", "06:00", "09:00", "12:00", "15:00", "18:00", "21:00"};
        double[] networkTrend = new double[8];
        double[] tempTrend = new double[8];
        double[] humidityTrend = new double[8];
        
        for (int i = 0; i < 8; i++) {
            networkTrend[i] = 97 + random.nextDouble() * 3;
            tempTrend[i] = 23 + random.nextDouble() * 4;
            humidityTrend[i] = 60 + random.nextDouble() * 10;
        }
        
        trendData.put("times", times);
        trendData.put("network", networkTrend);
        trendData.put("temperature", tempTrend);
        trendData.put("humidity", humidityTrend);
        data.put("trend", trendData);
        
        // 设备状态数据
        Map<String, Object> statusData = new HashMap<>();
        int[] statusValues = {8, 2, 1, 1};
        String[] statusNames = {"正常运行", "维护中", "故障", "离线"};
        statusData.put("values", statusValues);
        statusData.put("names", statusNames);
        data.put("status", statusData);
        
        return AjaxResult.success(data);
    }
} 